package com.zhangyu.eat.me;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.google.gson.Gson;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.zhangyu.eat.R;
import com.zhangyu.eat.base.bean.HotBean;
import com.zhangyu.eat.login.model.OnLoginListener;
import com.zhangyu.eat.me.gcfragment.HotFragment;
import com.zhangyu.eat.me.view.OnRefreshListener;
import com.zhangyu.eat.utils.OkHttpUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class GcFragment extends Fragment implements OnRefreshListener{


    @BindView(R.id.gc_search)
    ImageView gcSearch;
    @BindView(R.id.gc_gift)
    ImageView gcGift;
    @BindView(R.id.gc_bar)
    Toolbar gcBar;
    @BindView(R.id.gc_tab)
    TabLayout gcTab;
    @BindView(R.id.gc_pager)
    ViewPager gcPager;

    public GcFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_gc, container, false);
        ButterKnife.bind(this, view);

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        List<Fragment> fragments=new ArrayList<>();
        String []titles={"热门","男神","附近"} ;
        for (int i = 0; i <3 ; i++) {
            HotFragment fragment=new HotFragment();
            fragments.add(fragment);

        }
        GcAdapter adapter=new GcAdapter(getActivity().getSupportFragmentManager(),fragments,titles);
        gcPager.setAdapter(adapter);
        gcTab.setupWithViewPager(gcPager);
    }

    @Override
    public void onDownPullRefresh() {

    }

    @Override
    public void onLoadingMore() {

    }

    private class GcAdapter extends FragmentStatePagerAdapter{
        private List<Fragment> fragments = new ArrayList<>();
        private  String[] arrays;
        public GcAdapter(FragmentManager fm,List<Fragment> fragment,String [] array) {
            super(fm);
            this.arrays=array;
            this.fragments=fragment;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return arrays[position];
        }
    }

}
